#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/moduleparam.h>
#include <linux/sched.h>

MODULE_LICENSE("BSD");

static int pid = -1;
static int status = 0;

module_param(pid, int, S_IRUGO);
module_param(status, int, S_IRUGO);

/* 
 * task id defined in include/linux/sched.h *
 *
 * #define TASK_RUNNING        0 	(R)
 * #define TASK_INTERRUPTIBLE  1	(S)
 * #define TASK_UNINTERRUPTIBLE 2	(D)
 * #define __TASK_STOPPED      4
 * 
 */

static int _init(void){
	struct task_struct * p;
	printk(KERN_ALERT "_init\n");
	read_lock(&tasklist_lock);
	for_each_process(p){
		if(p->pid == pid){
			printk("change_pid_status: found pid:%d, and current state:%d\n",pid,p->state);
			set_task_state(p, status);
			printk(KERN_ALERT "set process:(%d) state:(%d)\n",pid, status);
			read_unlock(&tasklist_lock);
			return 0;
		}
	}
	printk("not found");
	read_unlock(&tasklist_lock);
	return 0;
}

static void _exit(void){
	printk(KERN_ALERT "_exit\n");
}

module_init(_init);
module_exit(_exit);
